package ug.co.icom.kyazze.healthticket;


import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

public class MainItemsFragment extends Fragment {
	

	public MainItemsFragment()
	{
		
	}

	
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.mainitems_layout, container, false);
        
        
        return rootView;
    }
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		ListView list = (ListView) getActivity().findViewById(R.id.listview1);
        list.setAdapter(new MainAdapter(getActivity(), 
        		android.R.layout.simple_list_item_1, R.id.textView1,
        		getResources().getStringArray(R.array.mainitemnames_array)));     
        registerForContextMenu(list);
        
		list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				switch (position) {

				case 0:
					Intent i = new Intent(getActivity().getApplicationContext(),
							AllergyListNames.class);
					startActivity(i);
					//
					break;
				default:

				}
			}
		});
		
	}
	
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		getActivity().getMenuInflater().inflate(R.menu.context_menu, menu);
		super.onCreateContextMenu(menu, v, menuInfo);
	}


	@Override
	public boolean onContextItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case R.id.view:
			Toast.makeText(getActivity().getApplicationContext(),
					"You have pressed Save Context Menu for add new",
					Toast.LENGTH_LONG).show();
			return true;
		case R.id.add_new:
			Intent i = new Intent(getActivity().getApplicationContext(), AllergyDataInput.class);
			startActivity(i);
			return true;
		case R.id.manage_shares:
			Toast.makeText(getActivity().getApplicationContext(),
					"You have pressed Edit Context Menu for manage shares",
					Toast.LENGTH_LONG).show();
			return true;

		}
		return false;
	}
}
